package webs.servlet.ServletDemoOne;
//表单提交数据，使用JDBC操作数据库

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

@WebServlet("/demo4")
public class servletTest_Four implements Servlet
{
    public static void jdbc(String name) throws SQLException
    {
        String sql="DELETE FROM stu WHERE Sname= ? ";
        Connection con=jdbcToolClass.Register();
        PreparedStatement statement=con.prepareStatement(sql);
        statement.setString(1,name);
        int count=statement.executeUpdate();
        jdbcToolClass.close(statement,con);
    }
    @Override
    public void init(ServletConfig servletConfig) throws ServletException
    {

    }
    @Override
    public ServletConfig getServletConfig()
    {
        return null;
    }
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException
    {
        String name=servletRequest.getParameter("studentName");
        try
        {
            jdbc(name);
        } catch (SQLException throwables)
        {
            throwables.printStackTrace();
        }
    }
    @Override
    public String getServletInfo()
    {
        return null;
    }
    @Override
    public void destroy()
    {

    }
}
